package com.ds.infrastructure.audit.collector.controller;

import com.ds.infrastructure.audit.collector.entity.KbaBehaviorComponent;
import com.ds.infrastructure.audit.collector.service.IMessageService;
import com.ds.infrastructure.audit.common.entity.KbaBehaviorWrapper;
import com.ds.infrastructure.audit.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/7/30
 */
@RestController
@RequestMapping(value = "/collector")
@Slf4j
@CrossOrigin
@Api(value = "Collector API Service", tags = {"Collector"})
@SuppressWarnings("all")
public class CollectorController {

    private final IMessageService messageService;

    public CollectorController(IMessageService messageService) {
        this.messageService = messageService;
    }

    @PostMapping(produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "Collect Data")
    public Result collect(@RequestBody @Valid KbaBehaviorWrapper wrapper) {
        //log.info("数据收集:{}", wrapper);
        messageService.processSingle(wrapper);
        return Result.success();
    }

    @PostMapping(value = "/batch", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "Collect Data Batch")
    public Result batch(@RequestBody @Valid KbaBehaviorComponent component) {
        //log.info("批量数据收集:{}", component.getBehaviors().size());
        messageService.process(component.getBehaviors());
        return Result.success();
    }

}
